import React, { useEffect, useState } from "react";
import Taro, { useRouter } from "@tarojs/taro";
import { Image } from "@tarojs/components";
import { imgUrlPrefix } from "@/common/config";

const Index: React.FC<{}> = () => {
  const [url, setUrl] = useState([]);
  const router = useRouter();
  const previewImg = (current) => {
    Taro.previewImage({
      current: imgUrlPrefix + current,
      urls: url.map((item) => imgUrlPrefix + item),
    });
  };

  useEffect(() => {
    console.log("src--->>", router.params.params);
    if (router.params.params) {
      setUrl(JSON.parse(router.params.params).img_url);
    }
  }, [router]);

  return url.map((item) => (
    <Image
      key={item}
      src={imgUrlPrefix + item}
      style="width:100%;"
      mode="widthFix"
      onClick={() => {
        previewImg(item);
      }}
    />
  ));
};

export default Index;
